package com.wzl.quickSort;

import java.util.Arrays;

/**
 * @author wuzhilang
 * @Title: QuickSort
 * @ProjectName ranking
 * @Description: 快速排序
 * @date 2019/7/319:50
 */
public class QuickSort {
	public static void sort(int sources[], int low, int high) {
		if (low < high) {
			int key = sources[low];
			int l = low;
			int h = high;
			int tmp;
			while (l < h) {
				while (l < h && sources[h] >= key) {
					h--;
				}
				if (l < h) {
					tmp = sources[l];
					sources[l] = sources[h];
					sources[h] = tmp;
				}
				while (l < h && sources[l] <= key) {
					l++;
				}
				if (l < h) {
					tmp = sources[l];
					sources[l] = sources[h];
					sources[h] = tmp;
				}
			}
			sort(sources,low, l-1);
			sort(sources,l+1,high);
		}
	}
	public static void main(String[] args) {
		int[] sources = {2,15,3,100,87,-1,34,25,77,80,62,11,7,2,55,22};
		sort(sources, 0, sources.length -1);
		System.out.println(Arrays.toString(sources));
	}

}
